package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.contracttemplate.LindiContractTemplateQueryVO;
import com.minimalist.common.entity.lindi.vo.contracttemplate.LindiContractTemplateVO;
import com.minimalist.common.feign.client.lindi.LindiContractTemplateFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地合同模板 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiContractTemplateFeignClientFallbackFactory extends BaseFallbackFactory<LindiContractTemplateFeignClient>{

    private static final Logger log = LoggerFactory.getLogger(LindiContractTemplateFeignClientFallbackFactory.class);

    @Override
    public LindiContractTemplateFeignClient create(Throwable cause){
        return new LindiContractTemplateFeignClient(){
            @Override
            public R<?> addContractTemplate(LindiContractTemplateVO contractTemplateVO){
                logServiceUnavailable("添加合同模板", contractTemplateVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "添加合同模板失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteContractTemplateByContractTemplateId(
                    Long contractTemplateId){
                logServiceUnavailable("删除合同模板", contractTemplateId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "删除合同模板失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateContractTemplateByContractTemplateId(
                    LindiContractTemplateVO contractTemplateVO){
                logServiceUnavailable("修改合同模板", contractTemplateVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "修改合同模板失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiContractTemplateVO>> getPageContractTemplateList(
                    LindiContractTemplateQueryVO queryVO){
                logServiceUnavailable("分页查询合同模板列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "分页查询合同模板列表失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiContractTemplateVO> getContractTemplateByContractTemplateId(
                    Long contractTemplateId){
                logServiceUnavailable("获取合同模板详情", contractTemplateId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "获取合同模板详情失败，服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteContractTemplateFileByFileId(Long fileId){
                logServiceUnavailable("根据文件ID删除合同模板", fileId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(),
                        "根据文件ID删除合同模板失败，服务不可用: " + cause.getMessage());
            }
        };
    }
}